<template>
  <div class="app-container">
    <el-form :model="queryParams_GZD" ref="queryForm_GZD" size="small" :inline="true" v-show="showSearch_GZD" label-width="68px">
      <el-form-item label="工单编号" prop="workOrderId">
        <el-input
          v-model="queryParams_GZD.workOrderId"
          placeholder="请输入工单编号"
          clearable
          @keyup.enter.native="handleQuery_GZD"
        />
      </el-form-item>
      <el-form-item label="客户编号" prop="customerId">
        <el-input
          v-model="queryParams_GZD.customerId"
          placeholder="请输入客户编号"
          clearable
          @keyup.enter.native="handleQuery_GZD"
        />
      </el-form-item>
      <el-form-item label="车辆入厂时间" prop="vehicleEntryTime">
        <el-input
          v-model="queryParams_GZD.vehicleEntryTime"
          placeholder="请输入车辆入厂时间"
          clearable
          @keyup.enter.native="handleQuery_GZD"
        />
      </el-form-item>
      <el-form-item label="预计完成时间" prop="estimatedCompletionTime">
        <el-input
          v-model="queryParams_GZD.estimatedCompletionTime"
          placeholder="请输入预计完成时间"
          clearable
          @keyup.enter.native="handleQuery_GZD"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery_GZD">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery_GZD">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd_GZD"
          v-hasPermi="['system:work_order_info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="singleGZD"
          @click="handleUpdate_GZD"
          v-hasPermi="['system:work_order_info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multipleGZD"
          @click="handleDelete_GZD"
          v-hasPermi="['system:work_order_info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport_GZD"
          v-hasPermi="['system:work_order_info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch_GZD.sync="showSearch_GZD" @queryTable="getListGZD"></right-toolbar>
    </el-row>

    <el-table v-loading="loading_GZD" :data="work_order_infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="工单编号" align="center" prop="workOrderId" />
      <el-table-column label="客户编号" align="center" prop="customerId" />
      <el-table-column label="车辆入厂时间" align="center" prop="vehicleEntryTime" />
      <el-table-column label="预计完成时间" align="center" prop="estimatedCompletionTime" />
      <el-table-column label="维修类型" align="center" prop="repairType" />
      <el-table-column label="维修内容" align="center" prop="repairContent" />
      <el-table-column label="维修状态" align="center" prop="repairStatus" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate_GZD(scope.row)"
            v-hasPermi="['system:work_order_info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete_GZD(scope.row)"
            v-hasPermi="['system:work_order_info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="totalGZD>0"
      :total="totalGZD"
      :page.sync="queryParams_GZD.pageNum"
      :limit.sync="queryParams_GZD.pageSize"
      @pagination="getListGZD"
    />

    <!-- 添加或修改工作单信息对话框 -->
    <el-dialog :title="titleGZD" :visible.sync="openGZD" width="500px" append-to-body>
      <el-form ref="formGZD" :model="formGZD" :rules="rulesGZD" label-width="80px">
        <el-form-item label="工单编号" prop="workOrderId">
          <el-input v-model="formGZD.workOrderId" placeholder="请输入工单编号" />
        </el-form-item>
        <el-form-item label="客户编号" prop="customerId">
          <el-input v-model="formGZD.customerId" placeholder="请输入客户编号" />
        </el-form-item>
        <el-form-item label="车辆入厂时间" prop="vehicleEntryTime">
          <el-input v-model="formGZD.vehicleEntryTime" placeholder="请输入车辆入厂时间" />
        </el-form-item>
        <el-form-item label="预计完成时间" prop="estimatedCompletionTime">
          <el-input v-model="formGZD.estimatedCompletionTime" placeholder="请输入预计完成时间" />
        </el-form-item>
        <el-form-item label="维修内容">
          <editor v-model="formGZD.repairContent" :min-height="192"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancelGZD">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWork_order_info, getWork_order_info, delWork_order_info, addWork_order_info, updateWork_order_info } from "@/api/4s_shop/work_order_info";

export default {
  name: "Work_order_info",
  data() {
    return {
      // 遮罩层
      loading_GZD: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      singleGZD: true,
      // 非多个禁用
      multipleGZD: true,
      // 显示搜索条件
      showSearch_GZD: true,
      // 总条数
      totalGZD: 0,
      // 工作单信息表格数据
      work_order_infoList: [],
      // 弹出层标题
      titleGZD: "",
      // 是否显示弹出层
      openGZD: false,
      // 查询参数
      queryParams_GZD: {
        pageNum: 1,
        pageSize: 10,
        workOrderId: null,
        customerId: null,
        vehicleEntryTime: null,
        estimatedCompletionTime: null,
        repairType: null,
        repairContent: null,
        repairStatus: null
      },
      // 表单参数
      formGZD: {},
      // 表单校验
      rulesGZD: {
        workOrderId: [
          { required: true, message: "工单编号不能为空", trigger: "blur" }
        ],
        customerId: [
          { required: true, message: "客户编号不能为空", trigger: "blur" }
        ],
        vehicleEntryTime: [
          { required: true, message: "车辆入厂时间不能为空", trigger: "blur" }
        ],
        estimatedCompletionTime: [
          { required: true, message: "预计完成时间不能为空", trigger: "blur" }
        ],
        repairType: [
          { required: true, message: "维修类型不能为空", trigger: "change" }
        ],
        repairContent: [
          { required: true, message: "维修内容不能为空", trigger: "blur" }
        ],
        repairStatus: [
          { required: true, message: "维修状态不能为空", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.getListGZD();
  },
  methods: {
    /** 查询工作单信息列表 */
    getListGZD() {
      this.loading_GZD = true;
      listWork_order_info(this.queryParams_GZD).then(response => {
        this.work_order_infoList = response.rows;
        this.totalGZD = response.total;
        this.loading_GZD = false;
      });
    },
    // 取消按钮
    cancelGZD() {
      this.openGZD = false;
      this.resetGZD();
    },
    // 表单重置
    resetGZD() {
      this.form = {
        workOrderId: null,
        customerId: null,
        vehicleEntryTime: null,
        estimatedCompletionTime: null,
        repairType: null,
        repairContent: null,
        repairStatus: null
      };
      this.resetForm("formGZD");
    },
    /** 搜索按钮操作 */
    handleQuery_GZD() {
      this.queryParams_GZD.pageNum = 1;
      this.getListGZD();
    },
    /** 重置按钮操作 */
    resetQuery_GZD() {
      this.resetForm("queryForm_GZD");
      this.handleQuery_GZD();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.workOrderId)
      this.singleGZD = selection.length!==1
      this.multipleGZD = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd_GZD() {
      this.resetGZD();
      this.openGZD = true;
      this.titleGZD = "添加工作单信息";
    },
    /** 修改按钮操作 */
    handleUpdate_GZD(row) {
      this.resetGZD();
      const workOrderId = row.workOrderId || this.ids
      getWork_order_info(workOrderId).then(response => {
        this.form = response.data;
        this.openGZD = true;
        this.titleGZD = "修改工作单信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["formGZD"].validate(valid => {
        if (valid) {
          if (this.form.workOrderId != null) {
            updateWork_order_info(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openGZD = false;
              this.getListGZD();
            });
          } else {
            addWork_order_info(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openGZD = false;
              this.getListGZD();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete_GZD(row) {
      const workOrderIds = row.workOrderId || this.ids;
      this.$modal.confirm('是否确认删除工作单信息编号为"' + workOrderIds + '"的数据项？').then(function() {
        return delWork_order_info(workOrderIds);
      }).then(() => {
        this.getListGZD();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport_GZD() {
      this.download('system/work_order_info/export', {
        ...this.queryParams_GZD
      }, `work_order_info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
